package com.GUI.lesson02;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestAction02 {
    public static void main(String[] args) {
        Frame frame = new Frame("开始-停止");
        Button button1 = new Button("start");
        Button button2 = new Button("stop");

        button2.setActionCommand("button-stop");
        MyMonitor myMonitor = new MyMonitor();

        button1.addActionListener(myMonitor);
        button2.addActionListener(myMonitor);

        //按钮位置
        frame.add(button1,BorderLayout.NORTH);
        frame.add(button2,BorderLayout.SOUTH);

        //按钮可见
        frame.setVisible(true);
    }
}
//事件监听
class MyMonitor implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {

        // e.getActionCommand() 获得按钮上的信息
        System.out.println("按钮被点击了：msg" + e.getActionCommand());
    }
}